<template>
	<u-tabbar 
		:height="platform === 'ios' ? '108':'100'"
		v-model="current" 
		:list="list" 
		icon-size="44" 
		active-color="#19B1B8" 
		inactive-color="#999999"
		@change="changeTab"
	></u-tabbar>
</template>

<script>
	export default {
		name: 'tab-bar',
		data() {
			return {
				list: [
					{
						iconPath: "/static/tab-icon/home.png",
						selectedIconPath: "/static/tab-icon/home-active.png",
						text: '任务大厅',
						customIcon: false,
						pagePath: '/pages/home/index'
					},
					{
						iconPath: "/static/tab-icon/mytask.png",
						selectedIconPath: "/static/tab-icon/mytask-active.png",
						text: '我的任务',
						customIcon: false,
						pagePath: '/pages/mytask/index'
					},
					{
						iconPath: "/static/tab-icon/user.png",
						selectedIconPath: "/static/tab-icon/user-active.png",
						text: '个人中心',
						customIcon: false,
						pagePath: '/pages/user/index'
					},
				],
				current: 0
			}
		},
		methods: {
			changeTab (){
				// 模拟双击tab，回到顶部
				// 200ms内再次点击
				if (this.tabClick) { 
					uni.pageScrollTo({
						scrollTop: 0,
						duration: 500
					})
				}
				this.tabClick = true;
				// 200ms内没有第二次点击，就当作单击
				setTimeout(() => {
					this.tabClick = false 
				}, 200)
			}
		}
	}
</script>
